package jrdcom.com.jrdcommonknowledge.Fragments.Serialize;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import jrdcom.com.jrdcommonknowledge.R;

/**
 * Created by longcheng on 2017/3/28.
 */

public class serializeFragments extends Fragment {
    public static final String TAG = serializeFragments.class.getSimpleName();
    @Bind(R.id.btn_serialize)
    Button btnSerialize;
    @Bind(R.id.btn_parcelable)
    Button btnParcelable;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.layout_serialieze, container, false);
        ButterKnife.bind(this, v);
        return v;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.btn_serialize, R.id.btn_parcelable})
    public void onClick(View view) {
        jrdCheckFragments fragments = new jrdCheckFragments();
        switch (view.getId()) {
            case R.id.btn_serialize:
                Bundle bundle = new Bundle();
                SerPerson person = new SerPerson();
                person.name = "Ser_wuzhaolin";
                person.age= 31;
                bundle.putSerializable("Ser_person", person);
                fragments.setArguments(bundle);
                break;
            case R.id.btn_parcelable:
                Bundle bundle1 = new Bundle();
                ParPerson person1 = new ParPerson();
                person1.name = "Par_wuzhaolin";
                person1.age = 31;
                bundle1.putParcelable("Par_person", person1);
                fragments.setArguments(bundle1);
                break;
        }
        getFragmentManager()
                .beginTransaction()
                .replace(R.id.main_fragment, fragments)
                .addToBackStack(jrdCheckFragments.TAG)
                .commit();
    }
}
